/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.gatech.ealf.keyboardassistanceplaf;

import edu.gatech.ealf.ettplaf.ETTModel;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.Timer;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.TextUI;
import javax.swing.text.BadLocationException;
import javax.swing.text.EditorKit;
import javax.swing.text.JTextComponent;
import javax.swing.text.Position.Bias;
import javax.swing.text.View;

/**
 *
 * @author Hemanth Pai
 */
public class KATextBoxUI extends TextUI implements KeyListener, FocusListener{
    
    private KAHelper kaHelper;
    
    public Timer characterDisplayTimer;
    
    public KATextBoxUI(){
        super();
    }
    
    public static ComponentUI createUI(JComponent c) {
        return new KATextBoxUI();
    }
    
    @Override
    public void installUI(JComponent c) {
        super.installUI(c);  
        KeyboardAssistanceLookAndFeel.getInstance().registerComponentInstallation(this, c);
        kaHelper = new KAHelper(c);
        c.addKeyListener(this);
    }

    @Override
    public void uninstallUI(JComponent c) {
        //System.out.println("uninstallUI called");
        KeyboardAssistanceLookAndFeel.getInstance().registerComponentUninstallation(this, c);
        c.removeKeyListener(this);
    }
    
    @Override
    public void paint(Graphics g, JComponent c) {
        
    }
    
    @Override
    public void update(Graphics g, JComponent c){
        
    }

   

    public void keyTyped(KeyEvent e) {
        kaHelper.keyTyped(e.getKeyChar());
        characterDisplayTimer = new Timer(KeyboardAssistanceLookAndFeel.getInstance().getCharacterDisplayTime(), kaHelper.hideDisplay);
        characterDisplayTimer.start();
    }

    public void keyPressed(KeyEvent e) {
        
    }

    public void keyReleased(KeyEvent e) {
        
    }

    @Override
    public Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException {
        return null;
    }

    @Override
    public Rectangle modelToView(JTextComponent t, int pos, Bias bias) throws BadLocationException {
        return null;
    }

    @Override
    public int viewToModel(JTextComponent t, Point pt) {
        return 0;
    }

    @Override
    public int viewToModel(JTextComponent t, Point pt, Bias[] biasReturn) {
        return 0;
    }

    @Override
    public int getNextVisualPositionFrom(JTextComponent t, int pos, Bias b, int direction, Bias[] biasRet) throws BadLocationException {
        return 0;
    }

    @Override
    public void damageRange(JTextComponent t, int p0, int p1) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void damageRange(JTextComponent t, int p0, int p1, Bias firstBias, Bias secondBias) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public EditorKit getEditorKit(JTextComponent t) {
        return null;
    }

    @Override
    public View getRootView(JTextComponent t) {
        return null;
    }

	public void focusGained(FocusEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	public void focusLost(FocusEvent arg0) {
	}
    
     
    

}
